package cn.lzy.head.service.impl;

import cn.lzy.common.copy.BeanCopierUtil;

import cn.lzy.head.mapper.mapper.HeadMapper;
import cn.lzy.head.mapper.pojo.Head;
import cn.lzy.head.service.Domain.HeadDO;
import cn.lzy.head.service.HeadService;
import cn.lzy.head.service.bo.HeadBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class HeadServiceImpl implements HeadService {

    @Autowired
    private HeadMapper headMapper;

    /**
     * 功能描述: 获得头部全部信息
     * @auther: lzy

     * @date: 2021/7/17 9:19
     * @return: java.util.List<cn.lzy.head.service.Domain.HeadDO>
     */
    @Override
    public List<HeadDO> getHeadFunction() {
        List<Head> heads = headMapper.selectAll();
        List<HeadDO> headDOS = BeanCopierUtil.copyList(heads, HeadDO.class);
        return headDOS;
    }

    /**
     * 功能描述: 添加头部信息
     * @auther: lzy
     * @param headBO:
     * @date: 2021/7/17 9:19
     * @return: int
     */
    @Override
    public int addHead(HeadBO headBO) {
        Head head = BeanCopierUtil.copyObj(headBO, Head.class);
        int insert = headMapper.insert(head);
        return insert;
    }

    /**
     * 功能描述: 删除头部信息
     * @auther: lzy
     * @param headBO:
     * @date: 2021/7/17 9:19
     * @return: int
     */
    @Override
    public int delHead(HeadBO headBO) {
        Head head = BeanCopierUtil.copyObj(headBO, Head.class);
        int delete = headMapper.delete(head);
        return delete;
    }

    /**
     * 功能描述: 修改头部信息
     * @auther: lzy
     * @param headBO:
     * @date: 2021/7/17 9:20
     * @return: int
     */
    @Override
    public int editHead(HeadBO headBO) {
        Head head = BeanCopierUtil.copyObj(headBO, Head.class);
        int i = headMapper.updateByPrimaryKeySelective(head);
        return i;
    }
}
